<?php

function getSiteTheme($template = 1)
{
	$selection = 'SELECT * FROM '.DB_PERFIX.'themes WHERE id='.$template.' LIMIT 1;';
	
	$result = mysql_query($selection);
	while($row = mysql_fetch_array($result))
	{ 
		$item = $row; 
		/*
		$item['id']					= $row['id'];
		$item['title'] 				= $row['title'];
		$item['site_id']			= $row['site_id'];
		$item['site_default'] 		= $row['site_default'];
		
		$item['theme_type']			= $row['theme_type'];
		$item['fixed_width']		= $row['fixed_width'];
		$item['horisontal_pos']		= $row['horisontal_pos'];
		
		$item['border_site']		= $row['border_site'];
		$item['border_content'] 	= $row['border_content'];
		
		$item['header']				= $row['header']; 
		$item['header_fixed']		= $row['header_fixed']; 
		$item['header_border'] 		= $row['header_border'];
		$item['header_hfb'] 		= $row['header_hfb'];
		$item['header_content'] 	= $row['header_content'];
		
		$item['footer']				= $row['footer'];
		$item['footer_fixed'] 		= $row['footer_fixed'];
		$item['footer_border'] 		= $row['footer_border'];
		$item['footer_hfb'] 		= $row['footer_hfb'];
		$item['footer_content'] 	= $row['footer_content'];
		
		$item['col_left']			= $row['col_left'];
		$item['col_left_border'] 	= $row['col_left_border'];
		$item['col_left_hfb'] 		= $row['col_left_hfb'];
		$item['col_left_content'] 	= $row['col_left_content'];
		
		$item['col_right']			= $row['col_right'];
		$item['col_right_border'] 	= $row['col_right_border'];
		$item['col_right_hfb'] 		= $row['col_right_hfb'];
		$item['col_right_content'] 	= $row['col_right_content'];
		
		$item['hfb_set'] 			= $row['hfb_set'];
		$item['hfb_com_set'] 		= $row['hfb_com_set'];
		*/
	}
	return $item;
}

function addSiteTemplate($title, $site)
{
	$title   = stripNonAlphaNum($title); 
	if(($title != '') && ($site > 0))
	{
		$insert  = "INSERT INTO ".DB_PERFIX."themes (`title`, `site_id`)"; 
		$insert .= "VALUES ('".$title."', ".$site.");";
		$result = mysql_query($insert);
	}
}

function updateTheme($id, $title, $type, $hfb_set, $hfb_com_set, $fixed_width=-1, $horisontal_pos=-1, $GridSystem=-1, $Bootstrap=-1, $border_site=-1, $border_content=-1, $header=-1, $footer=-1, $col_left=-1, $col_right=-1, $header_fixed=-1, $header_border=-1, $header_hfb=-1, $header_content=-1, $footer_fixed=-1, $footer_border=-1, $footer_hfb=-1, $footer_content=-1, $col_left_border=-1, $col_left_hfb=-1, $col_left_content=-1, $col_right_border=-1, $col_right_hfb=-1, $col_right_content=-1)
{
	$title   = stripNonAlphaNum($title); 
	if($title != '')
	{
		$update  = ' UPDATE '.DB_PERFIX.'themes SET ';
		$update .= ' `title` = "'.$title.'", ';
		$update .= ' `theme_type` = '.$type.', ';
		if($fixed_width > -1)
		{ $update .= ' `fixed_width` = '.$fixed_width.', '; }
		if($horisontal_pos > -1)
		{ $update .= ' `horisontal_pos` = '.$horisontal_pos.', '; }
		if($GridSystem > -1)
		{ $update .= ' `GridSystem` = '.$GridSystem.', '; }
		if($Bootstrap > -1)
		{ $update .= ' `Bootstrap` = '.$Bootstrap.', '; }
		if($border_site > -1)
		{ $update .= ' `border_site` = '.$border_site.', '; }
		if($border_site > -1)
		{ $update .= ' `border_site` = '.$border_site.', '; }
		if($border_content > -1)
		{ $update .= ' `border_content` = '.$border_content.', '; }
		if($header > -1)
		{ $update .= ' `header` = '.$header.', '; }
		if($header_fixed > -1)
		{ $update .= ' `header_fixed` = '.$header_fixed.', '; }
		if($header_hfb > -1)
		{ $update .= ' `header_border` = '.$header_border.', '; }
		if($header_hfb > -1)
		{ $update .= ' `header_hfb` = '.$header_hfb.', '; }
		if($header_content > -1)
		{ $update .= ' `header_content` = '.$header_content.', '; }
		if($footer > -1)
		{ $update .= ' `footer` = '.$footer.', '; }
		if($footer_fixed > -1)
		{ $update .= ' `footer_fixed` = '.$footer_fixed.', '; }
		if($footer_border > -1)
		{ $update .= ' `footer_border` = '.$footer_border.', '; }
		if($footer_hfb > -1)
		{ $update .= ' `footer_hfb` = '.$footer_hfb.', '; }
		if($footer_content > -1)
		{ $update .= ' `footer_content` = '.$footer_content.', '; }
		if($col_left > -1)
		{ $update .= ' `col_left` = '.$col_left.', '; }
		if($col_left_border > -1)
		{ $update .= ' `col_left_border` = '.$col_left_border.', '; }
		if($col_left_hfb > -1)
		{ $update .= ' `col_left_hfb` = '.$col_left_hfb.', '; }
		if($col_left_content > -1)
		{ $update .= ' `col_left_content` = '.$col_left_content.', '; }
		if($col_right > -1)
		{ $update .= ' `col_right` = '.$col_right.', '; }
		if($col_right_border > -1)
		{ $update .= ' `col_right_border` = '.$col_right_border.', '; }
		if($col_right_hfb > -1)
		{ $update .= ' `col_right_hfb` = '.$col_right_hfb.', '; }
		if($col_right_content > -1)
		{ $update .= ' `col_right_content` = '.$col_right_content.', '; }
		$update .= ' `hfb_set` = '.$hfb_set.', ';
		$update .= ' `hfb_com_set` = '.$hfb_com_set.' ';
		$update .= ' WHERE id='.$id.' LIMIT 1; ';
		$result = mysql_query($update);
	}
}

function deleteTheme($id)
{
	if($id > 0)
	{
		$theme = getSiteTheme($id);
		$result = mysql_query('DELETE FROM '.DB_PERFIX.'themes WHERE id='.$theme['id'].' LIMIT 1;');
		$result = mysql_query('DELETE FROM '.DB_PERFIX.'themes_css WHERE theme_id='.$theme['id'].';');
		
		if(is_dir(SITE_PATH.'templates/sites/'.$theme['site_id'].'/themes/'.$themeID))
		{ unlink(SITE_PATH.'templates/sites/'.$theme['site_id'].'/themes/'.$themeID); }
		
		if(is_dir(SITE_PATH.'templates/themes/'.$themeID))
		{ unlink(SITE_PATH.'templates/themes/'.$themeID); }
		return $result;
	}
}


function copyThemeToSite($id, $site_id)
{
	if(($site_id > 0) && ($id > 0))
	{
		$theme = getSiteTheme($id);
		if($theme)
		{
			$into	= '';
			$values = '';
			
			$into 	.= '`title`, ';
			$values .= '"'.$theme['title'].' Copy", ';
			$into 	.= '`site_id`, ';
			$values .= ''.$theme['site_id'].', ';
			$into 	.= '`site_default`, ';
			$values .= ''.$theme['site_default'].', ';
			
			$into 	.= '`theme_type`, ';
			$values .= ''.$theme['theme_type'].', ';
			$into 	.= '`fixed_width`, ';
			$values .= ''.$theme['fixed_width'].', ';
			$into 	.= '`horisontal_pos`, ';
			$values .= ''.$theme['horisontal_pos'].', ';
			
			$into 	.= '`GridSystem`, ';
			$values .= ''.$theme['GridSystem'].', ';
			
			$into 	.= '`Bootstrap`, ';
			$values .= ''.$theme['Bootstrap'].', ';
			
			$into 	.= '`border_site`, ';
			$values .= ''.$theme['border_site'].', ';
			$into 	.= '`border_content`, ';
			$values .= ''.$theme['border_content'].', ';
			
			$into 	.= '`header`, ';
			$values .= ''.$theme['header'].', '; 
			$into 	.= '`header_fixed`, ';
			$values .= ''.$theme['header_fixed'].', '; 
			$into 	.= '`header_border`, ';
			$values .= ''.$theme['header_border'].', ';
			$into 	.= '`header_hfb`, ';
			$values .= ''.$theme['header_hfb'].', ';
			$into 	.= '`header_content`, ';
			$values .= ''.$theme['header_content'].', ';
			
			$into 	.= '`footer`, ';
			$values .= ''.$theme['footer'].', ';
			$into 	.= '`footer_fixed`, ';
			$values .= ''.$theme['footer_fixed'].', ';
			$into 	.= '`footer_border`, ';
			$values .= ''.$theme['footer_border'].', ';
			$into 	.= '`footer_hfb`, ';
			$values .= ''.$theme['footer_hfb'].', ';
			$into 	.= '`footer_content`, ';
			$values .= ''.$theme['footer_content'].', ';
			
			$into 	.= '`col_left`, ';
			$values .= ''.$theme['col_left'].', ';
			$into 	.= '`col_left_border`, ';
			$values .= ''.$theme['col_left_border'].', ';
			$into 	.= '`col_left_hfb`, ';
			$values .= ''.$theme['col_left_hfb'].', ';
			$into 	.= '`col_left_content`, ';
			$values .= ''.$theme['col_left_content'].', ';
			
			$into 	.= '`col_right`, ';
			$values .= ''.$theme['col_right'].', ';
			$into 	.= '`col_right_border`, ';
			$values .= ''.$theme['col_right_border'].', ';
			$into 	.= '`col_right_hfb`, ';
			$values .= ''.$theme['col_right_hfb'].', ';
			$into 	.= '`col_right_content`, ';
			$values .= ''.$theme['col_right_content'].', ';
			
			$into 	.= '`hfb_set`, ';
			$values .= ''.$theme['hfb_set'].', ';
			$into 	.= '`hfb_com_set` ';
			$values .= ''.$theme['hfb_com_set'].'';
		
		
			
			$insert  = 'INSERT INTO '.DB_PERFIX.'themes ('.$into.')'; 
			$insert .= 'VALUES ('.$values.');';
			$result = mysql_query($insert);
		}
	}
	
}


function addThemeStyle($themeID, $type, $selector, $style)
{
	$selector   = trim($selector); 
	$style   = trim($style); 
	
	if(($themeID > 0) && ($selector != '') && ($selector != 'selector') && ($style != ''))
	{
		$insert  = 'INSERT INTO '.DB_PERFIX.'themes_css (`theme_id`, `type`, `selector`, `style`)'; 
		$insert .= 'VALUES ('.$themeID.', '.$type.', "'.$selector.'", "'.$style.'");';
		$result = mysql_query($insert);
	}
}

function updateThemeStyle($styleID, $selector, $style, $bg_image='')
{
	$selector   = trim($selector); 
	$style   = trim($style);
	
	if(($styleID > 0) && ($selector != '') && ($style != ''))
	{
		$update  = ' UPDATE '.DB_PERFIX.'themes_css SET ';
		$update .= ' `selector` = "'.$selector.'", ';
		if($bg_image != '')
		{ $update .= ' `bg_image` = "'.$bg_image.'", '; }
		$update .= ' `style` = "'.$style.'" ';
		$update .= ' WHERE id='.$styleID.' LIMIT 1; ';
		$result = mysql_query($update);
	}
}

function saveThemeCss($themeID, $siteID, $type)
{
	if($type == 0)
	{ $filename = 'theme.css'; }
	if($type == 1)
	{ $filename = 'headers.css'; }
	if($type == 2)
	{ $filename = 'footers.css'; }
	if($type == 3)
	{ $filename = 'buttons.css'; }
	if($type == 4)
	{ $filename = 'components.css'; }
	if($type == 5)
	{ $filename = 'modules.css'; }
	if($type == 6)
	{ $filename = 'borders.css'; }
	if($type == 7)
	{ $filename = 'menu.css'; }
	if($type == 8)
	{ $filename = 'typography.css'; }
	
	$output = '';
	$styleList = getThemeStyleList($themeID, $type);
	$store_path = SITE_PATH.'templates/themes/'.$themeID.'/'.$filename;
	if($styleList)
	{
		foreach($styleList as $selector)
		{ $output .= $selector['selector'].' { '.$selector['style'].' } '; }
		
		$output = str_replace('  ', ' ', $output);
		$output = str_replace(';  ', '; ', $output);
		$output = str_replace("\n", ' ', $output);
		$output = str_replace("\r", ' ', $output);
		$output = str_replace("\r\n", ' ', $output);
		
		if(file_exists($store_path))
		{ unlink($store_path); }
		file_put_contents($store_path,$output);
		
		saveThemeMinCss($themeID, $siteID);
	}
}

function saveThemeMinCss($themeID, $siteID)
{
	$filename = 'theme.min.css';
	
	if($type == 1)
	{ $filename = 'headers.css'; }
	if($type == 2)
	{ $filename = 'footers.css'; }
	if($type == 3)
	{ $filename = 'buttons.css'; }
	if($type == 4)
	{ $filename = 'components.css'; }
	if($type == 5)
	{ $filename = 'modules.css'; }
	if($type == 6)
	{ $filename = 'borders.css'; }
	if($type == 7)
	{ $filename = 'menu.css'; }
	if($type == 8)
	{ $filename = 'typography.css'; }
	
	$output = '';
	for($type=0; $type<9; $type++)
	{
		$styleList = getThemeStyleList($themeID, $type);
		
		if($styleList)
		{
			foreach($styleList as $selector)
			{ $output .= $selector['selector'].' { '.$selector['style'].' } '; }
		}
	}
	
	$store_path = SITE_PATH.'templates/themes/'.$themeID.'/'.$filename;
	$output = str_replace('  ', ' ', $output);
	$output = str_replace(';  ', '; ', $output);
	$output = str_replace("\n", ' ', $output);
	$output = str_replace("\r", ' ', $output);
	$output = str_replace("\r\n", ' ', $output);
	
	if(file_exists($store_path))
	{ unlink($store_path); }
	file_put_contents($store_path,$output);
}

function loadThemeHFBCss($themeID, $siteID, $type)
{
	if($themeID > 0)
	{
		if(!is_dir(SITE_PATH.'templates/themes/'.$themeID))
		{ mkdir(SITE_PATH.'templates/themes/'.$themeID); }
		if(!is_dir(SITE_PATH.'templates/themes/'.$themeID.'/images'))
		{ mkdir(SITE_PATH.'templates/themes/'.$themeID.'/images'); }
		
		$delete = 'DELETE FROM '.DB_PERFIX.'themes_css WHERE theme_id='.$themeID.' AND type='.$type.';';
		$result = mysql_query($delete);
		if($type == 1)
		{ $files = glob(SITE_PATH.'templates/themes/'.$themeID.'/images/headers/*'); }
		if($type == 2)
		{ $files = glob(SITE_PATH.'templates/themes/'.$themeID.'/images/footers/*'); }
		if($type == 3)
		{ $files = glob(SITE_PATH.'templates/themes/'.$themeID.'/images/buttons/*'); }
		if($type == 6)
		{ $files = glob(SITE_PATH.'templates/themes/'.$themeID.'/images/borders/*'); }
		if($type == 7)
		{ $files = glob(SITE_PATH.'templates/themes/'.$themeID.'/images/menu/*'); }
		if($files)
		{ 
			foreach($files as $file)
			{ unlink($file); }
		}
		if(!is_dir(SITE_PATH.'templates/themes/'.$themeID.'/images/headers'))
		{ mkdir(SITE_PATH.'templates/themes/'.$themeID.'/images/headers'); }
		if(!is_dir(SITE_PATH.'templates/themes/'.$themeID.'/images/footers'))
		{ mkdir(SITE_PATH.'templates/themes/'.$themeID.'/images/footers'); }
		if(!is_dir(SITE_PATH.'templates/themes/'.$themeID.'/images/buttons'))
		{ mkdir(SITE_PATH.'templates/themes/'.$themeID.'/images/buttons'); }
		if(!is_dir(SITE_PATH.'templates/themes/'.$themeID.'/images/borders'))
		{ mkdir(SITE_PATH.'templates/themes/'.$themeID.'/images/borders'); }
		if(!is_dir(SITE_PATH.'templates/themes/'.$themeID.'/images/menu'))
		{ mkdir(SITE_PATH.'templates/themes/'.$themeID.'/images/menu'); }
		
		if($type == 6)
		{ $selectBorder = ', border_site, border_content, header_border, footer_border, col_left_border, col_right_border'; }
		$select = 'SELECT header_hfb, footer_hfb, col_left_hfb, col_right_hfb, hfb_set, hfb_com_set '.$selectBorder.' FROM '.DB_PERFIX.'themes WHERE id='.$themeID.';';
		
		$result = mysql_query($select);
		while($row = mysql_fetch_array($result))
		{
			if($type == 6)
			{
				if($row['border_site'] > 0)
				{ 
					if($borders == '')
					{ $borders = $row['border_site'];  }
					else
					{ $borders = $borders.' , '.$row['border_site']; }
				}	
				if($row['border_content'] > 0)
				{ 
					if($borders == '')
					{ $borders = $row['border_content'];  }
					else
					{ $borders = $borders.' , '.$row['border_content']; }
				}
				if($row['header_border'] > 0)
				{ 
					if($borders == '')
					{ $borders = $row['header_border'];  }
					else
					{ $borders = $borders.' , '.$row['header_border']; }
				}
				if($row['footer_border'] > 0)
				{ 
					if($borders == '')
					{ $borders = $row['footer_border'];  }
					else
					{ $borders = $borders.' , '.$row['footer_border']; }
				}
				if($row['col_left_border'] > 0)
				{ 
					if($borders == '')
					{ $borders = $row['col_left_border'];  }
					else
					{ $borders = $borders.' , '.$row['col_left_border']; }
				}
				if($row['col_right_border'] > 0)
				{ 
					if($borders == '')
					{ $borders = $row['col_right_border'];  }
					else
					{ $borders = $borders.' , '.$row['col_right_border']; }
				}
			}
			
			if($row['header_hfb'] > 0)
			{ 
				if($hfb_sets == '')
				{ $hfb_sets = $row['header_hfb'];  }
				else
				{ $hfb_sets = $hfb_sets.' , '.$row['header_hfb']; }
			}	
			if($row['footer_hfb'] > 0)
			{
				if($hfb_sets == '')
				{ $hfb_sets = $row['footer_hfb'];  }
				else
				{ $hfb_sets = $hfb_sets.' , '.$row['footer_hfb']; }
			}	
			if($row['col_left_hfb'] > 0)
			{
				if($hfb_sets == '')
				{ $hfb_sets = $row['col_left_hfb'];  }
				else
				{ $hfb_sets = $hfb_sets.' , '.$row['col_left_hfb']; }
			}
			if($row['col_right_hfb'] > 0)
			{	
				if($hfb_sets == '')
				{ $hfb_sets = $row['col_right_hfb'];  }
				else
				{ $hfb_sets = $hfb_sets.' , '.$row['col_right_hfb']; }
			}
			if($row['hfb_set'] > 0)
			{
				if($hfb_sets == '')
				{ $hfb_sets = $row['hfb_set'];  }
				else
				{ $hfb_sets = $hfb_sets.' , '.$row['hfb_set']; }
			}
			if($row['hfb_com_set'] > 0)
			{	
				if($hfb_sets == '')
				{ $hfb_sets = $row['hfb_com_set'];  }
				else
				{ $hfb_sets = $hfb_sets.' , '.$row['hfb_com_set']; }
			}
			
		}
		
		if($hfb_sets != '')
		{
			$select = 'SELECT selector, style FROM '.DB_PERFIX.'admin_css WHERE type='.$type.' AND item_id=0;';
			$result = mysql_query($select);
			while($row = mysql_fetch_array($result))
			{
				mysql_query('DELETE FROM '.DB_PERFIX.'themes_css WHERE theme_id='.$themeID.' AND selector="'.$row['selector'].'";');
				addThemeStyle($themeID, $type, $row['selector'], $row['style']);
			}
			
			if($type == 1)
			{ $select = 'SELECT header FROM '.DB_PERFIX.'hfb_sets WHERE id IN ('.$hfb_sets.');'; }
			if($type == 2)
			{ $select = 'SELECT footer FROM '.DB_PERFIX.'hfb_sets WHERE id IN ('.$hfb_sets.');'; }
			if($type == 3)
			{ 
				$select  = 'SELECT id FROM '.DB_PERFIX.'buttons WHERE (';
				$select .= '(id IN (SELECT button FROM '.DB_PERFIX.'hfb_sets WHERE id IN ('.$hfb_sets.'))) OR ';  
				$select .= '(id IN (SELECT button FROM '.DB_PERFIX.'com_headers WHERE id IN (SELECT header FROM '.DB_PERFIX.'hfb_sets WHERE id IN ('.$hfb_sets.')))) OR ';
				$select .= '(id IN (SELECT button FROM '.DB_PERFIX.'com_footers WHERE id IN (SELECT footer FROM '.DB_PERFIX.'hfb_sets WHERE id IN ('.$hfb_sets.'))))';
				$select .= ');';
			}
			if($type == 6)
			{ 
				$select  = 'SELECT id FROM '.DB_PERFIX.'com_borders WHERE id>0 AND (id IN(SELECT border FROM '.DB_PERFIX.'hfb_sets WHERE id IN ('.$hfb_sets.'))';
				$select .= 'OR id IN(SELECT border2 FROM '.DB_PERFIX.'hfb_sets WHERE id IN ('.$hfb_sets.'))';
				if($borders)
				{ $select .= 'OR id IN ('.$borders.')'; }
				$select .= ');';
			}
			$result = mysql_query($select);
			
			$i=0;
			if($result)
			{
				while($row = mysql_fetch_array($result))
				{
					if($type == 1)
					{ $select2 = 'SELECT id, item_id, selector, style FROM '.DB_PERFIX.'admin_css WHERE type='.$type.' AND item_id >0 AND item_id='.$row['header'].' ORDER BY selector ASC;'; }
					if($type == 2)
					{ $select2 = 'SELECT id, item_id, selector, style FROM '.DB_PERFIX.'admin_css WHERE type='.$type.' AND item_id >0 AND item_id='.$row['footer'].' ORDER BY selector ASC;'; }
					if($type == 3)
					{ $select2 = 'SELECT id, item_id, selector, style FROM '.DB_PERFIX.'admin_css WHERE type='.$type.' AND item_id >0 AND item_id='.$row['id'].' ORDER BY selector ASC;'; }
					if($type == 6)
					{ $select2 = 'SELECT id, item_id, selector, style FROM '.DB_PERFIX.'admin_css WHERE type='.$type.' AND item_id >0 AND item_id='.$row['id'].' ORDER BY selector ASC;'; }
					$result2 = mysql_query($select2);

					while($row2 = mysql_fetch_array($result2))
					{
						$sytle = $row2['style'];
						if($type == 1)
						{ $styleNew = str_replace("images/","images/headers/",$sytle); }
						if($type == 2)
						{ $styleNew = str_replace("images/","images/footers/",$sytle); }
						if($type == 3)
						{ $styleNew = str_replace("images/","images/buttons/",$sytle); }
						if($type == 6)
						{ $styleNew = str_replace("images/","images/borders/",$sytle); }
						if($type == 7)
						{ $styleNew = str_replace("images/","images/menu/",$sytle); }
						
						addThemeStyle($themeID, $type, $row2['selector'], $styleNew);
						
						if($type == 1)
						{ $files = glob(HEADERS_PATH.'type_'.$row2['item_id'].'*'); }
						if($type == 2)
						{ $files = glob(FOOTERS_PATH.'type_'.$row2['item_id'].'*'); }
						if($type == 3)
						{ $files = glob(BUTTONS_PATH.'type_'.$row2['item_id'].'*'); }
						if($type == 6)
						{ $files = glob(BORDERS_PATH.'type_'.$row2['item_id'].'*'); }
						if($type == 7)
						{ $files = glob(MENU_PATH.'type_'.$row2['item_id'].'*'); }
						if($files)
						{ 
							foreach($files as $file)
							{
								if($type == 1)
								{ copy($file, SITE_PATH.'templates/themes/'.$themeID.'/images/headers/'.basename($file)); }
								if($type == 2)
								{ copy($file, SITE_PATH.'templates/themes/'.$themeID.'/images/footers/'.basename($file)); }
								if($type == 3)
								{ copy($file, SITE_PATH.'templates/themes/'.$themeID.'/images/buttons/'.basename($file)); }
								if($type == 6)
								{ copy($file, SITE_PATH.'templates/themes/'.$themeID.'/images/borders/'.basename($file)); }
								if($type == 7)
								{ copy($file, SITE_PATH.'templates/themes/'.$themeID.'/images/menu/'.basename($file)); }
							}
						}
					}
				}
			}
		}
		saveThemeCss($themeID, $siteID, $type);
	}
}

function deleteThemeCssSelector($id, $theme_id)
{
	if($id > 0)
	{
		$result = mysql_query('DELETE FROM '.DB_PERFIX.'themes_css WHERE theme_id='.$theme_id.' AND id='.$id.';');
		return $result;
	}
}
?>